
<?php
if (!defined('APP_PATH')) {
	define('APP_PATH', $_SERVER['DOCUMENT_ROOT']."/bdACPA");
}
require_once(APP_PATH.'/required.php');


function add_row($rowId){
	return "insert";	
}

function update_row($rowId){
	$pref = new Preference();
 	$pref->idpreference = intval($rowId);
 	$pref->idcentre = $GLOBALS['utilisateur']->idcentre;
 	$pref->champ = $_POST[$rowId."_c0"];
 	$pref->valeur = $_POST[$rowId."_c1"];
	$rowId = $GLOBALS['PREFERENCE_DAO']->modifier_preference($pref);
	
	return "update";	
}

function delete_row($rowId){
	return "delete";
}


//include XML Header (as response will be in xml format)
header("Content-type: text/xml");
//encoding may differ in your case
echo('<?xml version="1.0" encoding="utf-8" ?>'); 
//output update results
echo "<data>";


$ids = explode(",",$_POST["ids"]);
//for each row
for ($i=0; $i < sizeof($ids); $i++) { 
	$rowId = $ids[$i]; //id or row which was updated 
	$newId = $rowId; //will be used for insert operation	
	$mode = $_POST[$rowId."_!nativeeditor_status"]; //get request mode

	switch($mode){
		case "inserted":
			//row adding request
			$action = add_row($rowId);
		break;
		case "deleted":
			//row deleting request
			$action = delete_row($rowId);
		break;
		default:
			//row updating request
			$action = update_row($rowId);
		break;
	}	
	echo "<action type='".$action."' sid='".$rowId."' tid='".$newId."'/>";
	
}

echo "</data>";

?>